using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Saiket.BLL;

public partial class Admin_BlogAdmin : System.Web.UI.Page
{
    BusinessLogicLayer bll = new BusinessLogicLayer();
    protected void Page_Load(object sender, EventArgs e)
    {
        // SqlDataSource1.SelectParameters.Remove(SqlDataSource1.SelectParameters["BlogID"]);

        Page.MaintainScrollPositionOnPostBack = true;
    }


    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        
     //   Label BlogID = (Label)GridView1.Rows[e.NewSelectedIndex].FindControl("lblBlogID");
     //   Label1.Text = BlogID.Text;

        //CommentID
//        SqlDataSource1.UpdateParameters.Remove(SqlDataSource1.SelectParameters["BlogID"]
        //SqlDataSource1.SelectCommand = "SELECT  CommentID, (SELECT PostTitle FROM Blog WHERE (BlogID = BlogComment.BlogID)) AS PostTitle, CommentBy, CommentDesc, IPAddress, BlogID, IsPublished, CommentDate, Email FROM BlogComment WHERE BlogID=@BlogID";
        //SqlDataSource1.SelectParameters.Add("BlogID", BlogID.Text);
        //FormView1.DataSourceID = "SqlDataSource1";
        //FormView1.DataBind();
       
        

        // FormView1.
       
        
    }
    protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
    {
        try
        {
          
            bll.GenerateBlogRSS(Server.MapPath("../media/feeds/BlogRSS.xml"));
            //////////
            // commented as calculation is not done properly
            /////////////
            
            //string tags = e.Values["PostTags"].ToString().Trim().ToLower();
            //if (tags != null && tags != "")
            //{
            //    BusinessLogicLayer bll = new BusinessLogicLayer();
            //    bool isTagInserted=bll.SetTagsAfterInsert(tags);
            //}
        }
        catch
        {

        }
       
    }
       
    protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
    {
        try
        {

            bll.GenerateBlogRSS(Server.MapPath("../media/feeds/BlogRSS.xml"));
            //////////
            // commented as calculation is not done properly
            /////////////

            //string tags = e.NewValues["PostTags"].ToString().Trim().ToLower();
            //if (tags != null && tags != "")
            //{
            //    BusinessLogicLayer bll = new BusinessLogicLayer();
            //    bool isTagUpdated = bll.SetTagsAfterUpdate(tags);
            //}
        }
        catch
        {

        }
    }

    protected void DetailsView1_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        //string oldtags = e.OldValues["PostTags"].ToString();
        //string newtags = e.NewValues["PostTags"].ToString();
        //Hashtable BlogTags = new Hashtable();     

        //string[] OldTagsArray = oldtags.Split(',');
        //for (int i = 0; i < OldTagsArray.Length; i++)
        //{
        //    BlogTags[OldTagsArray[i]] ="1";
        //}

        //string[] newtagsArray = newtags.Split(',');
        //for (int i = 0; i < newtagsArray.Length; i++)
        //{
        //    BlogTags[newtagsArray[i]] ="0";
        //}
        
        
    }
    protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {

    }
}
